I am new to terraform. I was trying my bit on terrafrom
I have this bit in var.tfvars
variable "AWS_REGION" {
default = "me-south-1"
}
variable "AMI" {
type = "map"
default ={
me-south-1 = "ami-01b735b798*******"
us-east-1 = "ami-0c2a1acae666******"
}
}
and I am trying to create an ec2 in VPC by
resource "aws_instance" "terraform-web" {
ami = "${lookup(var.AMI, var.AWS_REGION)}"
instance_type = "t3.micro"
which is giving me the above-mentioned error.
Could anyone help me out with this ?
The way terraform works is:
variables.tf -- all variables are declared in this file
vars.tfvars -- all values are passed via this file. Name can be anything. should end with tfvars.
You don't need to use lookup just var.<variable_name> is enough!
ec2.tf:
resource "aws_instance" "terraform-web" {
ami = var.ami_id
instance_type = "t3.micro"
}
variables.tf
variable "ami_id" {
type = "string"
default = "xxxx"
}
vars.tfvars
ami_id = "yyyyy"